package com.dream.testtubebaby.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.content.Context;

import com.dream.testtubebaby.R;


/**
 * Created by Administrator on 15-8-3.
 */
public class MedicineDB {
	private Context mContext = null;
	private static MedicineDB singleInstance = null;
	private static String m_country_code = null;
	public static MedicineDB getSingleInstance(Context context) {
		String country_code = context.getResources().getConfiguration().locale
				.getCountry();
		if(m_country_code != null && !m_country_code.equals(country_code)){
			singleInstance = null;
		}
		if (singleInstance == null) {
			singleInstance = new MedicineDB(context);
			m_country_code = country_code;
		}
		return singleInstance;
	}

	private Map<String, String[]> multiValueMap = new HashMap<String, String[]>();

	private String[] injectionArray1 = null;
	private String[] injectionArrayQuantity1 = null;

	private String[] medicineArray1 = null;
	private String[] medicineArrayQuantity1 = null;

	private String[] medicineArray2 = null;
	private String[] medicineArrayQuantity2 = null;

	private String[] medicineArray3 = null;
	private String[] medicineArrayQuantity3 = null;

//	private String[] medicineArray4 = null;
//	private String[] medicineArrayQuantity4 = null;
//
//	private String[] medicineArray5 = null;
//	private String[] medicineArrayQuantity5 = null;
//
//	private String[] medicineArray6 = null;
//	private String[] medicineArrayQuantity6 = null;

	private MedicineDB(Context context) {
		mContext = context;
		injectionArray1 = mContext.getResources().getStringArray(
				R.array.injection1_array);

		injectionArrayQuantity1 = mContext.getResources().getStringArray(
				R.array.injection1_quantities_array);

		medicineArray1 = mContext.getResources().getStringArray(
				R.array.medicine1_array);

		medicineArrayQuantity1 = mContext.getResources().getStringArray(
				R.array.medicine1_quantities_array);

		medicineArray2 = mContext.getResources().getStringArray(
				R.array.medicine2_array);

		medicineArrayQuantity2 = mContext.getResources().getStringArray(
				R.array.medicine2_quantities_array);

		medicineArray3 = mContext.getResources().getStringArray(
				R.array.medicine3_array);

		medicineArrayQuantity3 = mContext.getResources().getStringArray(
				R.array.medicine3_quantities_array);

		for (String name : injectionArray1) {
			multiValueMap.put(name, injectionArrayQuantity1);
		}

		for (String name : medicineArray1) {
			multiValueMap.put(name, medicineArrayQuantity1);
		}

		for (String name : medicineArray2) {
			multiValueMap.put(name, medicineArrayQuantity2);
		}

		for (String name : medicineArray3) {
			multiValueMap.put(name, medicineArrayQuantity3);
		}

//		for (String name : medicineArray4) {
//			multiValueMap.put(name, medicineArrayQuantity4);
//		}
//
//		for (String name : medicineArray5) {
//			multiValueMap.put(name, medicineArrayQuantity5);
//		}
//
//		for (String name : medicineArray6) {
//			multiValueMap.put(name, medicineArrayQuantity6);
//		}
	}

	public String[] getMedicineNames() {
		List<String> names = new ArrayList<String>();

		for (String name : injectionArray1) {
			names.add(name);
		}

		for (String name : medicineArray1) {
			names.add(name);
		}

		for (String name : medicineArray2) {
			names.add(name);
		}

		for (String name : medicineArray3) {
			names.add(name);
		}
//		for (String name : medicineArray4) {
//			names.add(name);
//		}
//		for (String name : medicineArray5) {
//			names.add(name);
//		}
//		for (String name : medicineArray6) {
//			names.add(name);
//		}

		return (String[]) names.toArray(new String[0]);
	}

	public String[] getQuantities(String medicineName) {
		String[] quantities = multiValueMap.get(medicineName);
		if (quantities == null) {
			return new String[0];
		} else {
			return quantities;
		}
	}
}
